package com.work.cos.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.work.cos.domain.entity.AddressEntity;
import com.work.cos.mapper.base.IAddressMapper;
import com.work.cos.service.interfc.IAddressService;
import com.work.cos.util.page.PageInfo;

@Service
public class AddressServiceImpl implements IAddressService {

	@Autowired
	private IAddressMapper addressMapper;
	
	
	@Override
	public List<AddressEntity> findAllAddress(String userId,int pageNo, int pageSize) {
		return this.addressMapper.findAllPage(userId ,pageNo, pageSize);
	}
	
	@Override
	public List<AddressEntity> findAddressByUserId(String userId) {
		return this.addressMapper.findAddressByUserId(userId);
	}
	
	@Override
	public AddressEntity findDefaultAddress(String userId) {
		return this.addressMapper.findDefaultAddress(userId);
	}
	
	@Override
	public boolean addAddress(AddressEntity entity) {
		return this.addressMapper.save(entity) > 0;
	}
	
	
	@Override
	public boolean updateAddress(AddressEntity entity) {
		return this.addressMapper.updateAddress(entity) > 0;
	}
	
	@Override
	public boolean delAddress(Long id, String userId) {
		return this.addressMapper.delAddress(id, userId) > 0;
	}
	
	
	@Override
	public boolean setDefaultAddress(Long id, String userId) {
		boolean flag = this.addressMapper.setDefaultAddress(id, userId) > 0;
		if(flag){
			
			this.addressMapper.cancelDefaultAddress(userId, id);
		}
		return flag;
	}
}
